package com.example.animaldoctor03;

import java.io.Serializable;
import java.util.ArrayList;

import bingliandshuju.SingleDataofAll;
import commonClass.ADAQueryDiseaseByAnimalIDAction;
import commonClass.FunctionDispatcher;
import commonClass.RemoteActionsName;
import commonClass.FunctionDispatcher.IRequestCompeletListener;
import Modle.disease.Symptoms;
import Modle.disease.SymptomsCategorie;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Notification.Builder;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class IllnessDetail extends Activity {

	/* (non-Javadoc)
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 */
	
	private String animalIDofILLD = "";
	private ListView listviewofillnessdetail = null ;
	private ArrayList<Object> resultListofILLD = null;
	private void initElemofILLD(){
		setContentView(R.layout.illnessdetail);
		listviewofillnessdetail = (ListView)findViewById(R.id.listofillnessdetail);
	}
	
	private void getshujuofILLD(){
		
		Intent intentofbiaoguanzz = getIntent();
		Bundle dataofbiaoguanzz =  intentofbiaoguanzz.getExtras();
		SymptomsCategorie  dataduixiang = (SymptomsCategorie)dataofbiaoguanzz.getSerializable("shuju");
		animalIDofILLD = dataduixiang.getSymptomsCategorieID();
	
	}
	private ArrayList<Object> assemblyofILLD() {

		getshujuofILLD();
		ArrayList<Object> list = new ArrayList<Object>();
		list.add(animalIDofILLD);
		// Integer i = new Integer(10);
		// list.add(i);

		return list;
	}
private void bindingofILLD(final ArrayList<Object> list){

	try{
	
		 String[] resultofILLD = new String[list.size()];
		// list.toArray(new String[list.size()]);
		for (int i = 0; i < list.size(); i++) {
			
			
			System.out.println("-------------------------" + ((Symptoms) list.get(i)).getSymptomsCategorieName() );

			resultofILLD[i] =((Symptoms) list.get(i)).getSymptomsName() ;
		}
		
		
		ArrayAdapter<String> arrayAdapterofResultofillness = new ArrayAdapter<String>(
				this, android.R.layout.simple_list_item_1, resultofILLD);
		
		listviewofillnessdetail.setAdapter(arrayAdapterofResultofillness);
		
		listviewofillnessdetail.setOnItemClickListener(new OnItemClickListener() {

				public void onItemClick(AdapterView<?> parent, View view, int position,
						long id) {
					// TODO Auto-generated method stub
					
					//单例模式储存数据
					SingleDataofAll singleDataofAll1 = SingleDataofAll.getInstance();
					singleDataofAll1.setObject( (Symptoms)list.get(position));
					 
					 
					Bundle bundleofILLD= new Bundle ();
					bundleofILLD.putSerializable("shuju", (Serializable) list.get(position));
					Intent intentofILLD = new Intent(IllnessDetail.this,BiaoGuanZhengZhuang.class);
					intentofILLD.putExtras(bundleofILLD);
					startActivity(intentofILLD);
					finish();
					

				}	 
		 });
		}catch(NullPointerException e){
			android.app.AlertDialog.Builder builderofIND = new AlertDialog.Builder(IllnessDetail.this);
			builderofIND.setMessage("无数据,请用其他功能");
			builderofIND.create().show();
		}
		
	}	
	
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		initElemofILLD();
		
		ArrayList<Object> parasListofILLD = assemblyofILLD();
		final ArrayList<Object> resultListTofILLD = null;
		
		ADAQueryDiseaseByAnimalIDAction iActionofILLD = new ADAQueryDiseaseByAnimalIDAction();
		
		FunctionDispatcher functionDispacherofBGZZ = new FunctionDispatcher();
		functionDispacherofBGZZ.exceute(RemoteActionsName.QueryAllSymptomsBySymptomsCategorieID, parasListofILLD, iActionofILLD, new IRequestCompeletListener() {

			@Override
			public void doCompelet(ArrayList<Object> resultList) {
				// TODO Auto-generated method stub
				Log.v("ZhengZhuangFZ2", "post:" + resultList.toString());
				IllnessDetail.this.resultListofILLD = resultList;
				bindingofILLD(resultList);
			}
		},this);
		
	}

	
}
